package com.smrs.report.excel;

import java.util.List;

import org.apache.poi.ss.usermodel.Row;
import org.apache.poi.ss.usermodel.Sheet;

import com.jof.framework.excel.AbstractExcelExportTemplate;
import com.jof.framework.util.Pager;
import com.jof.framework.util.SpringApplicationContextHolder;
import com.smrs.deliver.service.DeliverHeaderService;
import com.smrs.report.model.ReportMonthlyDeliverModel;
import com.smrs.report.model.ReportSearchModel;
import com.smrs.security.enums.UserStatusEnum;
import com.smrs.security.enums.UserTypeEnum;

public class MonthlyDeliverReportTemplate extends AbstractExcelExportTemplate<ReportSearchModel>{

	@Override
	public String[] getSheetNames() {
		return new String[]{"月销售报表"};		
	}

	@Override
	public String[][] getTitles() {
		String[][] temp =  new String[][]{{"id","区域","门店名", "门店代码", "日期","开票金额","销售金额"}};
		return  temp;
		
	}

	@Override
	protected void buildBody(int sheetIndex) {
		Pager<ReportMonthlyDeliverModel> pager = new Pager<ReportMonthlyDeliverModel>();
		pager.setPageSize(Long.valueOf(Integer.MAX_VALUE));
		pager.setCountTotal(false);
		//ReportSearchModel searchModel = new ReportSearchModel();
		//searchModel.setPager(pager);
		//userSearchModel.setUser(this.parameters);
		ReportSearchModel searchModel = parameters;
		DeliverHeaderService deliverHeaderService = SpringApplicationContextHolder.getBean("deliverHeaderService");
		Pager<ReportMonthlyDeliverModel> users = deliverHeaderService.getDeliverReportOfMonthly(searchModel, pager);
		List<ReportMonthlyDeliverModel> resultList = users.getRecords();
		
		Sheet sheet = getSheet(sheetIndex);
		final int size = resultList.size();
		int startIndex = this.getBodyStartIndex(sheetIndex);
		for(int i = 0; i < size; i++){
			Row row = sheet.createRow(i+startIndex); 
			row.setHeight((short)300);
			int index = 0;
			ReportMonthlyDeliverModel deliverModel = resultList.get(i);
			createStyledCell(row,index++,deliverModel.getStoreId().toString(),this.bodyRowStyle);
			createStyledCell(row,index++,deliverModel.getRegionName(),this.bodyRowStyle);
			createStyledCell(row,index++,deliverModel.getStoreName(),this.bodyRowStyle);
			createStyledCell(row,index++,deliverModel.getStoreCode(),this.bodyRowStyle);
			createStyledCell(row,index++,deliverModel.getReportDate(),this.bodyRowStyle);
			createStyledCell(row,index++,deliverModel.getInvoiceAmount().toString(),this.bodyRowStyle);
			createStyledCell(row,index++,deliverModel.getSaleAmount().toString(),this.bodyRowStyle);
			//createStyledCell(row,index++,defaultDateFormat.format(user.getLastModifyDate()),this.bodyRowStyle);
			//createStyledCell(row,index++,user.getCreator(),this.bodyRowStyle);
			//createStyledCell(row,index++,user.getModifiedBy(),this.bodyRowStyle);
		}
	}
		
	

}
